#!/bin/sh

modem_param_list="\n
TZMODEM_AUTO_DIAL="TZ_ENABLE_AUTO_DIAL"\n
TZMODEM_APN0_AUTH_TYPE="TZ_DIALTOOL2_PPP_AUTH_TYPE"\n
TZMODEM_APN0_USERNAME="TZ_DIALTOOL2_PPP_USERNAME"\n
TZMODEM_APN0_PASSWORD="TZ_DIALTOOL2_PPP_PASSWORD"\n
TZMODEM_APN0_IP_STACK="TZ_DIALTOOL2_IP_STACK_MODE"\n
TZMODEM_APN0_MTU="TZ_DIALTOOL2_MTU_USB0"\n
TZMODEM_APN0_NAME="TZ_MUTILAPN1_APN_NAME"\n
TZMODEM_BAND_PREF="TZ_DIALTOOL2_LTE_BAND_PREF"\n
TZMODEM_PLMN_LOCK="TZ_DIALTOOL2_PLMN_LOCK"\n
TZMODEM_APN1_NAME="TZ_MUTILAPN1_APN_NAME"\n
TZMODEM_APN1_PROFILE="TZ_MUTILAPN1_PROFILE_NAME"\n
TZMODEM_APN1_USERNAME="TZ_MUTILAPN1_USERNAME"\n
TZMODEM_APN1_PASSWORD="TZ_MUTILAPN1_PASSWORD"\n
TZMODEM_APN1_AUTH_TYPE="TZ_MUTILAPN1_AUTH_TYPE"\n
TZMODEM_APN1_IP_STACK="TZ_MUTILAPN1_IP_STACK_MODE"\n
TZMODEM_APN1_MTU="TZ_MUTILAPN1_MTU"\n
TZMODEM_APN1_ENABLE="TZ_MUTILAPN1_ENABLE"\n
TZMODEM_APN2_NAME="TZ_MUTILAPN2_APN_NAME"\n
TZMODEM_APN2_PROFILE="TZ_MUTILAPN2_PROFILE_NAME"\n
TZMODEM_APN2_USERNAME="TZ_MUTILAPN2_USERNAME"\n
TZMODEM_APN2_PASSWORD="TZ_MUTILAPN2_PASSWORD"\n
TZMODEM_APN2_AUTH_TYPE="TZ_MUTILAPN2_AUTH_TYPE"\n
TZMODEM_APN2_IP_STACK="TZ_MUTILAPN2_IP_STACK_MODE"\n
TZMODEM_APN2_MTU="TZ_MUTILAPN2_MTU"\n
TZMODEM_APN2_ENABLE="TZ_MUTILAPN2_ENABLE"\n
"

param_file_modem=/tmp/.param_file_modem
extern_file=$1

if [ ! -e "${extern_file}" ]; then
	exit
fi

cat $extern_file | grep TZMODEM > ${param_file_modem}


#
while read line
do
        name=`echo $line | awk -F "=" '{print$1}' | awk '{print $2}'`
        value=`echo $line | awk -F "=" '{print$2}' | awk -F '"' '{print $2}'`

        name_in_modem_param=`echo -e ${modem_param_list} | grep ${name} | awk -F "=" '{print $2}'`
        if [ -n "${name_in_modem_param}" ]; then
        	uci set tozed.modem.${name_in_modem_param}="${value}"
        fi

done < ${param_file_modem}

cfg -c
